package com.heima.jopo.servlet;

import com.heima.jopo.obj.UserInfo;
import com.heima.jopo.web.RegUser;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//url-pattern的使用
@WebServlet(name = "httpServlet", urlPatterns = "/niubiservlet")
public class HttpServlet extends javax.servlet.http.HttpServlet {

    //创建servlet


    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("----------------------------第三章--------------------------");
        //创建servlet对象
        RegUser regUser = new RegUser();
        //创建用户信息对象
        UserInfo userInfo = new UserInfo();

        //获取WEB前段输入的值
        String zh = request.getParameter("zh");
        String passwrod = request.getParameter("pwd");
        String username = request.getParameter("username");
        String sex = request.getParameter("sex");
        String year = request.getParameter("year");
        String mounth = request.getParameter("mounth");
        String day = request.getParameter("day");

        String dayth = "" + year + "-" + mounth + "-" + day;
        String now = request.getParameter("now");



        //给属性初始化值
        userInfo.setPhone(zh);
        userInfo.setPasswrod(passwrod);
        userInfo.setUsername(username);
        userInfo.setSex(sex);
        userInfo.setBirthday(dayth);
        userInfo.setCareer(now);



        //调用注册方法传信息过去
        regUser.reg(userInfo);

        request.getAttribute("userinfo");
        //响应跳转
//     request.getRequestDispatcher("web-app/html/login.jsp").forward(request,response);
        response.sendRedirect("html/login.jsp");

    }


}
